<template>
  <JobInfoCard v-for="i in CardsData_show"
    :title="i.job_name"
    :author="i.enterprise_name"
    :content="i.job_type"
    :times="i.release_date"
    :img_src="i.img_src"
    :experience="i.working_area"
    :education="i.education_require"
    :money="i.salary_range"
    :jobInfo_id="i.job_infor_id"
    :tap_infos="i.tap_infos"
  ></JobInfoCard>
</template>

<script>

import JobInfoCard from './JobInfoCard'
import axios from 'axios'

export default {
  name: 'JobInfoCards',
  components:{JobInfoCard},
  data(){
    return{
      CardsData:[],
      CardsData_show:[],
    }
  },
  methods:{
    deteleObject(obj) {
      var uniques = [];
      var stringify = {};
      for (var i = 0; i < obj.length; i++) {
        var keys = Object.keys(obj[i]);
        keys.sort(function(a, b) {
          return (Number(a) - Number(b));
        });
        var str = '';
        for (var j = 0; j < keys.length; j++) {
          str += JSON.stringify(keys[j]);
          str += JSON.stringify(obj[i][keys[j]]);
        }
        if (!stringify.hasOwnProperty(str)) {
          uniques.push(obj[i]);
          stringify[str] = true;
        }
      }
      uniques = uniques;
      return uniques;
    }
  },
  created () {
    const _this=this
    axios.get('http://localhost:8080/getJobInfo_and_taps')
      .then(function (response) {
        _this.CardsData=response.data
        let i=0

        sessionStorage.setItem('job_info_data_in_search',JSON.stringify(_this.CardsData))
        //console.log(sessionStorage.getItem('job_info_data_in_search'))

        sessionStorage.setItem('all_taps','')
        for (;i < _this.CardsData.length;i=i+1){
          //console.log(_this.CardsData[i].tap_infos)
          if(_this.CardsData[i].tap_infos){
            _this.CardsData[i].tap_infos = _this.CardsData[i].tap_infos.slice(0,_this.CardsData[i].tap_infos.length-1)
            let temp = ''
            temp = sessionStorage.getItem('all_taps')
            if(i > 0){
              temp = temp + '，'
            }
            temp = temp + _this.CardsData[i].tap_infos
            sessionStorage.setItem('all_taps',temp)
            _this.CardsData[i].tap_infos = _this.CardsData[i].tap_infos.split('，')
          }
        }
        //_this.CardsData_show = JSON.parse(JSON.stringify(_this.CardsData))



        if(sessionStorage.getItem('job_info_data_out_search')){
          _this.CardsData_show=JSON.parse(sessionStorage.getItem('job_info_data_out_search'))
          //console.log(sessionStorage.getItem('job_info_data_out_search'))
          _this.CardsData_show = _this.deteleObject(_this.CardsData_show)
        }else {
          _this.CardsData_show = JSON.parse(JSON.stringify(_this.CardsData))

        }
        //console.log(_this.CardsData)

        // window.addEventListener('job_info_data_out_search', (e) => {
        //   console.log(e);
        // });

        // //测试数据，前端
        // _this.CardsData[0].tap_infos='互联网，前端，程序员'
        // _this.CardsData[0].tap_infos = _this.CardsData[0].tap_infos.split('，')
        // let temp = ''
        // temp = sessionStorage.getItem('all_taps')
        // temp = temp + '，互联网，前端，程序员'
        // sessionStorage.setItem('all_taps',temp)

      })
      .catch(function (error) {
        console.log(error);
      });
  },
  watch:{

  }
}
</script>

<style scoped>

</style>

